package operation;

import book.BookList;

import java.util.Scanner;

public class BorrowOperation implements Operation {
    @Override
    public void work(BookList book) {
        System.out.println("借阅图书...");
        System.out.println("请输入你要借的书名：");
        Scanner sc = new Scanner(System.in);
        String borrowedName = sc.nextLine();
        int currentSize = book.getUsedsize();
        for (int i = 0; i < currentSize; i++) {
            if (borrowedName.equals(book.getBooks(i).getName())) {
                if (book.getBooks(i).isIsborrowed() == true) {
                    System.out.println("已经被借出!");
                    return;
                }
                book.getBooks(i).setIsborrowed(true);
                System.out.println("借阅成功！");
                return;
            }
        }
        System.out.println("没有找到此书，借阅失败！");
    }
}
